package ex.com

import org.hamcrest.core.Is;
import org.hamcrest.core.IsNot;
import org.hamcrest.core.IsNull;

import grails.test.*

import ex.com.Product
import ex.com.ProductVendor
import ex.com.Vendor

class ProductTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
		
		mockDomain Product
		mockDomain Vendor
		mockDomain ProductVendor
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testSomething() {
		ex.com.Product.get(1)
		
		def product
        product = new Product([name:"product1"])
        product.save()
				
		def vendor
		vendor=new Vendor([name:"vendor1"])
		vendor.save()
		
		def productVedor
		productVedor = new ProductVendor(product:product, vendor:vendor);
		productVedor.save()
		
		product = new Product(name:"product2");
		product.save()
		
		productVedor = new ProductVendor(product:product, vendor:vendor);
		productVedor.save()

		
		product = new Product(name:"product12");
		product.save()

		vendor=new Vendor(name:"vendor12")
		vendor.save()
		
		productVedor = new ProductVendor(product:product, vendor:vendor);
		productVedor.save()		
		
		def p1 = Product.findByName("product1")
		assertNotNull(p1)
		assertEquals(p1.name, "product1")
		try{
			Product.findByNameTmp("test")
			fail()
		}catch(Exception e){
		}
    }
}
